package com.mj.mafeed.adapter;

import java.util.List;

import com.mj.mafeed.R;
import com.mj.mafeed.bean.AreaJSON;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

/**
 * 地区下拉列表
 * @author zhaominglei
 * @date 2014-12-17
 * 
 */
public class AreaSpinnerAdapter extends BaseAdapter {
	private List<AreaJSON> areas;
	private Context context;
	
	public AreaSpinnerAdapter(Context context, List<AreaJSON> areas) {
		super();
		this.context = context;
		this.areas = areas;
	}

	public List<AreaJSON> getAreas() {
		return areas;
	}


	public void setAreas(List<AreaJSON> areas) {
		this.areas = areas;
	}

	@Override
	public int getCount() {
		return areas.size();
	}

	@Override
	public Object getItem(int position) {
		return areas.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
//		RelativeLayout relativeLayout;
//		if (convertView != null) {
//			relativeLayout = (RelativeLayout) convertView;
//		} else {
//			relativeLayout = (RelativeLayout) View.inflate(context,
//					R.layout.area_item, null);
//		}
//		TextView areanameText = (TextView) relativeLayout.findViewById(R.id.area_item_areaname);
//		areanameText.setText(areas.get(position).getName());
//		areanameText.setTag(areas.get(position).getAreaId());
//		return relativeLayout;
		TextView areanameText;
		if (convertView != null) {
			areanameText = (TextView) convertView;
		} else {
			areanameText = (TextView) View.inflate(context, R.layout.area_item, null);
		}
		areanameText.setText(areas.get(position).getName());
		areanameText.setTag(areas.get(position).getAreaId());
		return areanameText;
	}
}
